package com.zd.kids.ui.view;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.blankj.utilcode.util.AppUtils;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;
import com.lxj.xpopup.core.CenterPopupView;
import com.lxj.xpopup.interfaces.SimpleCallback;
import com.zd.kids.R;
import com.zd.kids.ui.activity.MainTypeActivity;

import androidx.annotation.NonNull;

/**
 * @ClassName: com.zd.kids.ui.view
 * @Description:
 * @Author: hyy
 * @Date: 2020/6/19
 * @Time: 10:21 AM
 */
public class DownApkPopupWindow extends CenterPopupView {

    public DownApkPopupWindow(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void init() {
        super.init();
        initPopupWionw();
    }

    private void initPopupWionw() {
        prompt_title = findViewById(R.id.tv_prompt_title);
        btn_confirm = findViewById(R.id.btn_confirm);
        btn_cancel = findViewById(R.id.img_delete);
        tv_prompt_content = findViewById(R.id.tv_prompt_content);
        progress_bar = findViewById(R.id.progress_bar);


        btn_confirm.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                if (callBack != null) {
                    callBack.confirm();
                }
            }
        });

        btn_cancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {


                if (callBack != null) {
                    callBack.cancle();
                }

                dismiss();
            }
        });


    }


    public void setPromptTitle(String title) {
        prompt_title.setText(title);
    }


    public void setForce(boolean force) {
        btn_cancel.setVisibility(force ? View.GONE : View.VISIBLE);
    }

    public String getPromptContent() {
        return tv_prompt_content.getText().toString();
    }

    public void setPromptContent(String content) {
        tv_prompt_content.setText(content);
    }

    public void setDownProgress(int progress) {
        progress_bar.setProgress(progress);
    }


    public void hidePrograss() {
        progress_bar.setVisibility(View.GONE);
    }

    public void showPrograss() {
        progress_bar.setVisibility(View.VISIBLE);

    }

    public CallBack getCallBack() {
        return callBack;
    }

    public void setCallBack(CallBack callBack) {
        this.callBack = callBack;
    }

    private CallBack callBack;

    @Override
    protected int getImplLayoutId() {
        return R.layout.popupwindow_down_apk_layout;
    }


    public interface CallBack {
        abstract void confirm();

        abstract void cancle();

        void onShow();
    }

    TextView prompt_title;
    TextView btn_confirm;
    ImageView btn_cancel;
    TextView tv_prompt_content;
    ProgressBar progress_bar;

    public void showView() {
        new XPopup.Builder(getContext())
                .dismissOnTouchOutside(false)
                .dismissOnBackPressed(false)
                .setPopupCallback(new SimpleCallback() {
                    @Override
                    public void onShow() {
                        callBack.onShow();

                        prompt_title = findViewById(R.id.tv_prompt_title);
                        btn_confirm = findViewById(R.id.btn_confirm);
                        btn_cancel = findViewById(R.id.img_delete);
                        tv_prompt_content = findViewById(R.id.tv_prompt_content);
                        progress_bar = findViewById(R.id.progress_bar);
                    }

                    @Override
                    public void onDismiss() {

                    }
                })
                .asCustom(this)
                .show();

    }
}
